package com.deity.news.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import net.hongliang.util.FieldUtil;
import net.hongliang.util.HtmlUtil;

import com.opensymphony.webwork.ServletActionContext;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionSupport;

public class MyActionSupport extends ActionSupport {

	private StringBuffer err = new StringBuffer();

	public String getErr() {
		return err.toString();
	}

	public FieldUtil getFieldutil() {
		return FieldUtil.getInstance();
	}

	public HtmlUtil getHtmlutil() {
		return HtmlUtil.getInstance();
	}

	public UserRoleUtil getRoleutil() {
		return UserRoleUtil.getInstance();
	}

	public String getUrl() {
		return ActionContext.getContext().getName() + ".action";
	}

	public String getUsername() {
//		return (String) ActionContext.getContext().getSession().get(
//				Constant.SESSION_USER);
		HttpServletRequest request=ServletActionContext.getRequest();
		Cookie userCookie = CookieManager.getCookie(request, Constant.COOKIE_NAME);
		String username = "";
		if(userCookie!=null){
			String cookieValue = userCookie.getValue();
			username = cookieValue.split("/")[0];
		}else{
			username="";
		}
		return username;
	}

	public void setErr(String e) {
		err.append("<li>");
		err.append(e);
		err.append("</li>\n");
	}
}
